package com.bonc.rms.service.impl.tms;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bonc.odk.logmanager.LogManager;
import com.bonc.rms.entity.tms.School;
import com.bonc.rms.mapper.WastageInfoMapper;
import com.bonc.rms.service.tms.WastageInfoService;
import com.bonc.rms.utils.impl.EmployeeRRUtilImpl;
import com.bonc.rms.utils.impl.WastageInfoUtilImpl;

@Service
@Transactional
public class WastageInfoServiceImpl implements WastageInfoService {
	@Autowired
	EmployeeRRUtilImpl employeeRRUtilImpl;
	@Autowired
	WastageInfoMapper wastageInfoMapper;
	@Autowired
	WastageInfoUtilImpl wastageInfoUtilImpl;

	/**
	 * 离职员工毕业学校排名
	 */
	@Override
	public List<School> getWastageSchoolInfo(Integer departmentStandardId) {
		LogManager.Method("Int Service : WastageInfoServiceImpl -> getWastageSchoolInfo");
		List<Integer> departmentIdlist = new ArrayList<>();
		departmentIdlist = wastageInfoUtilImpl
				.getDepartmentId(departmentStandardId);
		List<School> schoolList = new ArrayList<>();
		if ((departmentIdlist == null || departmentIdlist.size() == 0)
				&& departmentStandardId > 2) {
		}else{
			
			schoolList = wastageInfoMapper.getSchoolList(departmentIdlist,
					departmentIdlist.size());
		}
		LogManager.Method("Out Service : WastageInfoServiceImpl -> getWastageSchoolInfo");
		return schoolList;
	}

	@SuppressWarnings("null")
	@Override
	public Map<String, String> getWastageSalaryInfo(Integer departmentId) {
		LogManager.Method("Int Service : WastageInfoServiceImpl -> getWastageSalaryInfo");
		Map<String, String> map = new HashMap<>();
		List<String> leaveEmployee = new ArrayList<>();
		leaveEmployee = wastageInfoUtilImpl.getLeaveEmployee(departmentId);
		int salary = 0;

		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		int e = 0;
		if (leaveEmployee != null || leaveEmployee.size() > 0) {

			for (String employeeId : leaveEmployee) {

				String adjustDateStr = wastageInfoUtilImpl
						.getRecordSalary(employeeId);

				if (adjustDateStr == null || adjustDateStr.equals("")) {

					salary = employeeRRUtilImpl.getTrialMonthSalary(employeeId);

					if (salary <= 3000) {
						a++;
					} else if (salary <= 7000) {
						b++;
					} else if (salary <= 10000) {
						c++;
					} else if (salary <= 30000) {
						d++;
					} else {
						c++;
					}

				} else {
					salary = employeeRRUtilImpl.getAdjustMonthSalary(
							employeeId, adjustDateStr);
					if (salary <= 3000) {
						a++;
					} else if (salary <= 7000) {
						b++;
					} else if (salary <= 10000) {
						c++;
					} else if (salary <= 30000) {
						d++;
					} else {
						c++;
					}
				}

			}
		}
		map.put("3k以下", a + "");
		map.put("3k-7k", b + "");
		map.put("7k-10k", c + "");
		map.put("10k-30k", d + "");
		map.put("30k以上", e + "");
		LogManager.Method("Out Service : WastageInfoServiceImpl -> getWastageSalaryInfo");
		return map;
	}

}
